package com.lhm.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: lhm
 * @Date: 2020/12/6 13:56
 * 4
 */
@Configuration
public class MyImgConfig implements WebMvcConfigurer {

    @Value("${upload.dir}")
    private String filePath;

    /**
     * 不配置这个的话上传成功后需要重启服务器才能访问到图片
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/imgs/**").addResourceLocations("file:"+filePath);
    }
}
